﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Yugi.Client.Card;

namespace Yugi.Client.Converter
{
    partial class ConvertData
    {
        private void ConvertData_CARD_SETCONG(byte[] input)
        {
            
            int card_id = (int)input[0];
            int diem = BitConverter.ToInt32(input.ToArray(), 1);
            Result.Add(card_id);
            Result.Add(diem);
        }
        private void ConvertData_CARD_SETTHU(byte[] input)
        {
           
            int card_id = (int)input[0];
            int diem = BitConverter.ToInt32(input.ToArray(), 1);
            Result.Add(card_id);
            Result.Add(diem);
            
        }
        //------------------------------API------------------------------------
        private void ConvertData_API_DRAWCARD(byte[] input)
        {
            //int player_id = (int)input[0];
            //int card_type_id = (int)input[1];
            //int card_id = (int)input[2];

            int player_id = DecodeByte(ref input);
            int card_type_id = DecodeInt(ref input);
            int card_id = DecodeByte(ref input);

            YBaseCard card = GetCard(card_type_id);
            card.ID = card_id;
            Result.Add(player_id);
            Result.Add(card);
        }
        private void ConvertData_API_SPECIALSUMMON(byte[] input)
        {

            //int player_id = (int)input[0];
            //int card_type_id = (int)input[1];
            //int card_id = (int)input[2];

            int player_id = DecodeByte(ref input); 
            int card_type_id = DecodeInt(ref input);
            int card_id = DecodeByte(ref input); 

            //Zone zone = (Zone)input[3];

            Zone zone = (Zone)input[0];
            YBaseCard card = GetCard(card_type_id);
            card.ID = card_id;
            Result.Add(player_id);
            Result.Add(card);
            Result.Add(zone);
        }
        private void ConvertData_API_SPECIALSUMMON_XONG(byte[] input)
        {
            //int player_id = (int)input[0];
            //int card_type_id = (int)input[1];
            //int card_id = (int)input[2];

            int player_id = DecodeByte(ref input);
            int card_type_id = DecodeInt(ref input);
            int card_id = DecodeByte(ref input); 

            YBaseCard card = GetCard(card_type_id);
            card.ID = card_id;

            //int x = 4-(int)input[3];
            //int y = 6-(int)input[4];
            //Zone from = (Zone)input[5];
            //YMSG trangthai = (YMSG)input[6];

            int x = 4-(int)input[0];
            int y = 6-(int)input[1];
            Zone from = (Zone)input[2];
            YMSG trangthai = (YMSG)input[3];

            Result.Add(player_id);
            Result.Add(card);
            Result.Add(x);
            Result.Add(y);
            Result.Add(from);
            Result.Add(trangthai);

        }
        private void ConvertData_API_CHANGECONTROL(byte[] input)
        {
            int player_id1 = (int)input[0];
            int card_id1 = (int)input[1];
            int player_id2 = (int)input[2];
            Result.Add(player_id1);
            Result.Add(card_id1);
            Result.Add(player_id2);
        }
        //-----------------------Xoa Bai-----------------------------------
        private void ConvertData_CARD_XOABAI_TAY(byte[] input)
        {
            int id = (int)input[0];
            Result.Add(id);
        }
        private void ConvertData_CARD_XOABAI_GRAVEYARD(byte[] input)
        {
            int player_id = (int)input[0];
            int card_id1 = (int)input[1];
            Result.Add(player_id);
            Result.Add(card_id1);
        }
        private void ConvertData_CARD_MOVETO_GRAVEYARD(byte[] input)
        {
            //int player_id = (int)input[0];
            //int card_type_id = (int)input[1];
            //int card_id1 = (int)input[2];

            int player_id = DecodeByte(ref input);
            int card_type_id = DecodeInt(ref input);
            int card_id1 = DecodeByte(ref input);

            YBaseCard card = GetCard(card_type_id);
            card.ID = card_id1;
            Result.Add(player_id);
            Result.Add(card);
        }
        //------------------------Request-----------------------------------
        private void ConvertData_REQUEST_ASK(byte[] input)
        {
            
            int id = (int)input[0];
            int len = (int)input[1];
            string message= UTF8Encoding.UTF8.GetString(input, 2, len);

            Result.Add(id);
            Result.Add(message);
            
        }
        private void ConvertData_REQUEST_CHONBAI_DOITHU_BAN(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            YType type = (YType)input[2];
            Result.Add(id);
            Result.Add(number);
            Result.Add(type);
        }
        private void ConvertData_REQUEST_CHONBAI_NGUOICHOI_BAN(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            YType type = (YType)input[2];
            Result.Add(id);
            Result.Add(number);
            Result.Add(type);
        }
        private void ConvertData_REQUEST_CHONBAI_NGUOICHOI_TAY(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            YType type = (YType)input[2];
            Result.Add(id);
            Result.Add(number);
            Result.Add(type);
        }
        private void ConvertData_REQUEST_CHONBAI_DOITHU_TAY(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            YType type = (YType)input[2];
            Result.Add(id);
            Result.Add(number);
            Result.Add(type);
        }
        private void ConvertData_REQUEST_CHONBAI_TRENBAN(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            YType type = (YType)input[2];
            Result.Add(id);
            Result.Add(number);
            Result.Add(type);
        }
        private void ConvertData_REQUEST_CHONBAI_DANHSACH(byte[] input)
        {
            int id = (int)input[0];
            int number = (int)input[1];
            int total = (int)input[2];

            Result.Add(id);
            Result.Add(number);
            List<int> list_id= new List<int>();
            int temp;
            for (int i = 0; i < total; i++)
            {
                temp= (int)input[3+i];
                list_id.Add(temp);
            }

            Result.Add(list_id);
        }
        //-----------------------Move Card----------------------------------//
        private void ConvertData_API_MOVECARD(byte[] input)
        {
            //int type_id = (int)input[0];
            //int id = (int)input[1];

            int type_id = DecodeInt(ref input);
            int id = DecodeByte(ref input);

            //Zone from = (Zone)input[2];
            //Zone to = (Zone)input[3];

            Zone from = (Zone)input[0];
            Zone to = (Zone)input[1];
            Result.Add(type_id);
            Result.Add(id);
            Result.Add(from);
            Result.Add(to);
        }
        private void ConvertData_API_MOVECARD_DOITHU(byte[] input)
        {
            
            //Zone from = (Zone)input[0];
            //Zone to = (Zone)input[1];
            //int soluong = (int)input[2];

            Zone from = (Zone)DecodeByte(ref input);
            Zone to = (Zone)DecodeByte(ref input);
            int soluong = (int)DecodeByte(ref input);

            Result.Add(from);
            Result.Add(to);
            if(soluong!=0)
            {
                //int type_id = (int)input[3];
                //int id = (int)input[4];
                int type_id = (int)DecodeInt(ref input);
                int id = (int)DecodeByte(ref input);
                Result.Add(type_id);
                Result.Add(id);
            }
            
        }
        //-----------------------Wait Active--------------------------------------------
        private void ConvertData_CARD_WAITING_ACTIVE_BEGIN(byte[] input)
        {
            
        }
        private void ConvertData_CARD_WAITING_ACTIVE_END(byte[] input)
        {

        }
        //-----------------------Response------------------------------------
        private void ConvertSendData_RESPONE_CHONBAI_DOITHU_BAN(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);

            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }
        }
        private void ConvertSendData_RESPONE_CHONBAI_NGUOICHOI_BAN(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);

            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }   
        }
        private void ConvertSendData_RESPONE_CHONBAI_TRENBAN(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);

            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }
        }
        private void ConvertSendData_RESPONE_CHONBAI_NGUOICHOI_TAY(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);

            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }
        }
        private void ConvertSendData_RESPONE_CHONBAI_DOITHU_TAY(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);

            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }
        }
        private void ConvertSendData_RESPONE_CHONBAI_DANHSACH(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);
            for (int i = 0; i < (byte)(int)input[1]; i++)
            {
                Result_Send.Add((byte)(int)input[2 + i]);
                if ((int)input[2 + i] == -1) return;
            }
        }
        private void ConvertSendData_RESPONE_CANCEL(object[]input)
        {
           
        }
        private void ConvertSendData_RESPONE_ASK(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
            Result_Send.Add((byte)(int)input[1]);
        }
        private void ConvertSendData_API_SPECIALSUMMON_XONG(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);//     id
            //Result_Send.Add((byte)(int)input[1]);//     type_id
            Result_Send.AddRange(BitConverter.GetBytes((int)input[1]));//     type_id
            Result_Send.Add((byte)(int)input[2]);//     card_id
            Result_Send.Add((byte)(int)input[3]);//     x
            Result_Send.Add((byte)(int)input[4]);//     y
            Result_Send.Add((byte)(Zone)input[5]);//    zone
            Result_Send.Add((byte)(YMSG)input[6]);//    trangthai
        }
        //--------------------------------Active----------------------------//
        private void ConvertData_CARD_LIST_CANEXCUTE(byte[] input)
        {
            int count = input[0];
            for (int i = 1; i <= count; i++)
            {
                Result.Add((int)input[i]);
            }
        }
        private void ConvertSendData_CARD_EXCUTE_SUMMON(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
        }
        private void ConvertSendData_CARD_EXCUTE_SPELL(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
        }
        private void ConvertSendData_CARD_EXCUTE_TRAP(object[] input)
        {
            Result_Send.Add((byte)(int)input[0]);
        }
       
    }
}
